package com.wtwd.campus.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wtwd.campus.dao.InformationMapper;
import com.wtwd.campus.dao.NotificationMapper;
import com.wtwd.campus.entity.Information;
import com.wtwd.campus.entity.InformationVO;
import com.wtwd.campus.entity.Notification;
import com.wtwd.campus.service.InformationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class InformationServiceImpl implements InformationService {
    @Autowired
    private InformationMapper informationMapper;

    @Override
    public int addInformation(Information data) {
        return informationMapper.addInformation(data);
    }

    @Override
    public List<Notification> getNotificationListByCondition(Notification data) {
        return null;
    }

    @Override
    public Information getInformationById(Integer id) {
        return informationMapper.getInformationById(id);
    }

    @Override
    public Long getBiggestTimeBySchoolId(Integer schoolId) {
        return informationMapper.getBiggestTimeBySchoolId(schoolId);
    }

    @Override
    public List<Information> getInformationByTimeAndSchoolId(Integer schoolId, Long time, Integer count) {
        Long end=time+1000*60*60*24;
        Integer min=count*10;
        return informationMapper.getInformationByTimeAndSchoolId(schoolId,time,end,min);
    }

    @Override
    public Map<String,Object> getInformationListByCondition(InformationVO data) {
        if(data.getType() == 0){
            data.setType(null);
        }
        Page<Information> page=new Page<>(data.getCurPage(),data.getPageSize());
        IPage<Information> iPage=informationMapper.getInformationListByCondition(data,page);
        long total = iPage.getTotal();
        List<Information> records = iPage.getRecords();
/*        records.stream().forEach(e->{
            e.setContent(e.getContent().replace("<br/>"," "));
        });*/
        Map<String,Object> result=new HashMap<>();
        result.put("total",total);
        result.put("data",records);
        return result;
    }
}
